'use strict';function _tl(a,b,k=_Ky){k.storage.local.get(a,g=>{setTimeout(()=>b(_tp(g||_9g(a)||{})))})}function _Dd(a,b){_Ky.storage.local.set(_Fd(a),()=>{b&&setTimeout(b)})}function _Fd(a){a=a.sc();"trigActList"in a&&(a.trigActList=a.trigActList.toJSON());if("customEntities"in a){a.customEntities=a.customEntities.sc();for(let b in a.customEntities)a.customEntities[b]=[...a.customEntities[b]]}return a}
function _tp(a){"trigActList"in a&&(a.trigActList=_Dr(a.trigActList));if("customEntities"in a)for(let b in a.customEntities)a.customEntities[b]={}.add(a.customEntities[b]);return a}function _Uw(a,b,k){a=a.sc().del(Object.keys(b));_Pt(a)?k(b):_tl(a,g=>k(g.add(b)))}let _qf=(...a)=>b=>{_tl({[a[0]]:null},k=>b(_Kg(k,...a)))};
{let a={},b=Symbol(),k=Symbol();var _v=function(...l){let r=l.pop();for(let n of l)"string"==typeof n&&(n=n.split(".")),l=""===n.slice(-1)[0]?(n.pop(),b):k,_ih(a,...n,l,[]).add(r)},_Qk=function(...l){l[l.length-1].runOnce=!0;return _v(...l)},_Ao=function(...l){l[l.length-1].grpChng=-1;return _v(...l)};let g=function(l){function r(t,p,w){if(t){t[k]&&n.push({funcs:t[k],path:p});t[b]&&0==w.length&&n.push({funcs:t[b],path:p});p=p.concat(w.slice(0,1));let c=w.slice(1);r(t["*"],p,c);r(t[w[0]],p,c)}}let n=
[];r(a,[],l);return n},m,v=[],x=0;var _pd=function(l,r,n=300,t){clearTimeout(m);v.push({keyPath:_3y(l),value:r,callback:t});m=setTimeout(()=>{let p=v;v=[];let w={};for(let c of p)w[c.keyPath[0]]=null;++x;_tl(w,c=>{for(let e of p)_ih(c,...e.keyPath,e.value,NaN);_Dd(c,()=>{const e=_fy();let d={};for(let h of p){if(!e){var f=g(h.keyPath);for(let q of f){f=q.funcs;const y=_ih(d,q.path.join(),[]);for(let z=f.length;z--;){const u=f[z];u.grpChng?u.grpChng!=x&&(u.grpChng=x,u(c,q.path)):u.runOnce?(f.splice(z,
1),u(c,q.path)):0>y.indexOf(u)&&(y.push(u),u(c,q.path))}}}h.callback&&setTimeout(()=>h.callback(e))}})})},n)}}
let _ks=(a,b=0)=>(k=_Qu)=>{let g=new _do;for(let [m,v]of a)_pd(m.split("."),v,b,g.onReady());g.setCallback((...m)=>{m=m.filter(v=>v)[0];k(m)})},_2o=()=>a=>_Ky.storage.local.get(null,b=>a(b.del("LOCAL"))),_Hh=_wj(function*(a){var b=window==_hf;if(b||(yield _9h(_Pr(a),"permMsgs/newSttgs"))){var k=yield g=>_tl({LOCAL:{}},g);yield g=>_Ky.storage.local.clear(g);yield g=>_Ky.storage.local.set(a.add(k),g);if(_fy())b||_yt("ERROR: \n\n"+_fy(),{type:"error"});else{yield g=>_hf._4h(g);if(b){(yield g=>_gs(a,
g))||_Ky.permissions.remove({permissions:["background"]});b=yield _By({url:_Ky.runtime.getURL(_gi)});for(let g of b)_Ky.tabs.reload(g.id)}else _xo("New settings imported successfully. <hr b=3> Reloading now...",1200).onHide(()=>location.href="");return!0}}}),_qj=_wj(function*(a){_hf._Ed&&(yield _Zp("set",a));yield _Hh(a)});function _Gd(a){for(let [b,k]of _ey(a))_Gd(k),_Pt(k)&&(_Mg(a)?a.splice(b,1):k&&"object"==typeof k&&"value"==b&&a.name||delete a[b]);return a}
let _Qj=_wj(function*(){if((yield _qf("trigActList")).length||!_Pt(_Gd(yield _qf("customEntities"))))return!1;let a=_Gd(yield _qf("mouseGest"));return!_Kg(a,"triggers","preconds")&&(!_Kg(a,"triggers","begin")&&!_Kg(a,"triggers","end")||"other"!=_Kg(a,"triggers","preset"))});
function _bk(a,b,k,g){function m(c,e){for(let d=1;;++d)if(!(d in c||d in e))return d}function v(c,e,d){c.trigActList.del(e);for(let [f,h,q]of _Rs(c.customEntities.menuSpec))"type"==f&&"action"==h&&q.content==e&&(q.content=+d)}function x(c,e,d,f,h){h||(c.customEntities[e][f]=c.customEntities[e][d]);delete c.customEntities[e][d];d=e+":"+d;e=e+":"+f;e=JSON.stringify(_Fd(c)).replace(RegExp(`"${d}"`,"g"),`"${e}"`);c.add(_tp(JSON.parse(e)))}function l(c,e){return 0==_bo(_oi(c),_oi(e))}function r(c,e,d=
0){return JSON.stringify(e).replace(/"([a-z]+):(\d+)"/ig,(f,h,q)=>(h=15>d&&_Kg(c.customEntities[h],q,"value"))?'"'+r(c,h,d+1)+'"':f)}function n(c,e){return r(a,c)==r(b,e)}function t(){do{var c=!1;for(let e of Object.keys(b.trigActList)){let d=b.trigActList[e];for(let [f,h]of a.trigActList)!d.disabled&&h.disabled||h.title&&d.title&&!l(h.title,d.title)||!n([h.triggers,h.actions],[d.triggers,d.actions])||(c=!0,v(b,e,f),!h.title&&d.title&&(h.title=d.title),!h.icon&&d.icon&&(h.icon=d.icon))}}while(c)}
function p(c,e,d){for(let [,f]of d)f.sctnId==c.id&&(f.sctnId=e);c.id=e}function w(){for(let [c,e]of _ey(b.sections))for(let d of a.sections)l(e.name,d.name)&&(p(e,d.id,b.trigActList),b.sections.splice(c,1))}for(let [,c]of a)_Gd(c);for(let [,c]of b)_Gd(c);(function(){for(let [c,e]of b.trigActList)if(a.trigActList.has(c)){let d=m(b.trigActList,a.trigActList);b.trigActList.set(d,e,b.trigActList.getPos(c));v(b,c,d)}})();(function(){a:for(;;){for(let [e,d]of b.customEntities)for(let [f]of d){var c=a.customEntities[e]||
{};if(f in c){c=m(d,c);x(b,e,f,c);continue a}}break}})();g&&t();(function(){a:for(;;){for(let [c,e]of b.customEntities)for(let [d,f]of e)if(f.name)for(let [h,q]of a.customEntities[c]||{})if(l(f.name,q.name)){if(n(q.value,f.value))x(b,c,d,h,!0);else{let y=f.name.replace(/\((\d+)\)$/,(z,u)=>`(${+u+1})`);l(y,f.name)&&(y=f.name+" (2)");b.customEntities[c][d].name=y}continue a}break}})();(function(){let c=b.sections.reduce((d,f,h)=>(d[f.id]=h,d),{}),e=a.sections.reduce((d,f,h)=>(d[f.id]=h,d),{});for(let d of b.sections)if(d.id in
e){let f=m(c,e);p(d,f,b.trigActList)}})();k&&w()}function _ze(a,b,k=!1){a.trigActList=k?b.trigActList.add(a.trigActList):a.trigActList.add(b.trigActList);a.sections.push(...b.sections);for(let [g,m]of b.customEntities)_ih(a.customEntities,g).add(m);for(let [g,m]of b.toolbarBtns)_Kg(a.toolbarBtns[g],"icon","img")||(a.toolbarBtns[g]=m);return a};
